<html>
<meta charset="UTF-8">
<head><title>生意宝接口测试</title>
    <script type="text/javascript" src="/js/jquery/jquery.js"></script>
    <script type="text/javascript" src="/js/md5/md5.js"></script>
    <script type="text/javascript" src="/js/aes/AESUtil.js"></script>
    <script type="text/javascript" src="/js/aes/mode-ecb.js"></script>
    <script type="text/javascript" src="/js/aes/aes.js"></script>
    <script type="text/javascript" src="/js/post/QuQu.js"></script>
</head>
<body>
<table width="100%">
    <tr>
        <td> 接口URL </td>
        <td colspan="4" > <input style="width:400px" name="url" value="http://121.43.167.172:8066/syb/controller/p" /></td>
    </tr>
    <tr>
        <td> 加密方式 </td>
        <td> <select name="encryptiontype">
            <option value="1">AES</option>
            <option value="3">明文</option>
        </select>
        </td>
        <td> accountid </td>
        <td>
            <input name="accountid" value="100000000064" />
        </td>
    </tr>
    <tr>
        <td> 商户key: </td>
        <td>
            <input name="merchantkey" value="e14d1b981fa2771c" />
        </td>
        <td> 应用key: </td>
        <td>
            <input name="appkey" value="123f3d446229cb93" />
        </td>
    </tr>
    <tr>
        <td> appcode: </td>
        <td>
            <input name="appcode" value="100004" />
        </td>
        <td> requesttype: </td>
        <td>
            <input name="requesttype" value="1" />
        </td>
    </tr>
    <tr>
        <td> terminaltype: </td>
        <td>
            <input name="terminaltype" value="1" />
        </td>
        <td> terminalno: </td>
        <td>
            <input name="terminalno" value="1" />
        </td>
    </tr>
    <tr>
        <td> 参数名： </td>
        <td> <input name="key" value="" /></td>
        <td> 参数值： </td>
        <td> <input name="val" value="" /></td>

        <td>
            <input type="button" name="addParam" value="增加参数" />
            <input type="button" name="delParam" value="删除参数" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="button" name="submit" value="提交" /> &nbsp; &nbsp; <input type="button" name="clear" value="清除" />
        </td>
    </tr>
    <tr>
        <td colspan="5">
					<textarea style="height:300px;width:960px"></textarea>
        </td>
    </tr>
</table>
</body>
<script>
    $(function(){
        $(document).delegate('input[name="addParam"]','click',function(){
            var html = $(this).parent().parent().html();
            $(this).parent().parent().after('<tr>'+html+'</tr>');
        }).delegate('input[name="delParam"]','click',function(){
            if($('input[name="delParam"]').length>1){
                $(this).parent().parent().remove();
            }
        }).delegate('input[name="submit"]','click',function(){

            var postdata = {
                accountid:$('input[name="accountid"]').val(),
                encryptiontype:$('select[name="encryptiontype"]').val()
            };
            var data={};
            $('input[name="key"]').each(function(i,o){
                data[$(o).val()]=$($('input[name="val"]')[i]).val();
            });

            if($('select[name="encryptiontype"]').val()=='1'){//AES
                var str = JSON.stringify(data);
                var sign = CryptoJS.MD5(str+$('input[name="appkey"]').val()).toString();
                postdata.data=aesEncrypt(str,$('input[name="merchantkey"]').val());
                postdata.sign=sign;
            }
            else if($('select[name="encryptiontype"]').val()=='3'){//明文
                var str = JSON.stringify(data);
                var sign = CryptoJS.MD5(str+$('input[name="appkey"]').val()).toString();
                postdata.data=str;
                postdata.sign=sign;
            }

            QuQu.post({
                url:$('input[name="url"]').val(),
                appcode:$('input[name="appcode"]').val(),
                postdata:postdata
            },true,function(data){
                var datatext = '';
                console.log(data);
                $('textarea').append('返回:'+JSON.stringify(data).replace('"{','{').replace('}"','}').replace(/\\/g,'')+'\r\n');
                if($('select[name="encryptiontype"]').val()=='1'){
                    console.log(data.data);
                    // console.log(JSON.parse(data.data).result);

                    if(data.data.result != ''){
                        datatext= aesDecrypt(data.data.result,$('input[name="merchantkey"]').val()).replace('"{','{').replace('}"','}').replace(/\\/g,'');
                    }
                }
                $('textarea').append('解密后:result='+datatext+'\r\n');
            })

        });

    }).delegate('input[name="clear"]','click',function(){
        $('textarea').text('');
    })

</script>
</html>
